<template>
	<view class="container" :style="[{paddingTop:CustomBar+50+'px'}]">
		<cu-custom bgColor="bg-colorP" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">巧厨乐精选</block>
		</cu-custom>
		<view class="header" :style="[{top:CustomBar+'px'}]">
			<view class="left" @click="show">
				<image src="https://xarkbucket.oss-cn-hangzhou.aliyuncs.com/resources/qiao-all-categories.png" mode=""></image>
				<text>{{nowType.catName?nowType.catName:'全部分类'}}</text>
				<image src="https://xarkbucket.oss-cn-hangzhou.aliyuncs.com/resources/qiao-lower-triangle.png" class="position top"
				 mode="" v-if="!isShow"></image>
				<image src="https://xarkbucket.oss-cn-hangzhou.aliyuncs.com/resources/qiao-upper-triangle.png" class="position down"
				 mode="" v-if="isShow"></image>
			</view>
			<view class="tui-rolling-search" @click='nav' :data-url="'/pages/cloudMall/cookSearch'">
				<icon type="search" :size='13' name="search" color='#999'></icon>
				<swiper vertical autoplay circular interval="8000" class="tui-swiper">
					<swiper-item v-for="(item,index) in hotSearch" :key="index" class="tui-swiper-item">
						<view class="tui-hot-item">{{item}}</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<view class="q-content">
			<view class="q-item" v-for="(item,index) in goodList" :key="index"  @click="nav" :data-url="'/pages/cloudMall/productDetail?id='+item.id">
				<image :src="item.goodsImg" mode=""></image>
				<view class="q-info">
					<view class="">
						{{item.goodsName}}
					</view>
					<view class="">
						<view class="tags">
							<!-- <uni-tag  inverted="false" :text="" size="small" :type="'warning'"></uni-tag> -->
							<view class="tag" v-for="(tag,i) in item.accreds_data" :key="i">
								<image :src="tag.img" mode=""></image>
								<text>{{tag.name}}</text>
							</view>
						</view>
						<view class="">
							<text class="text-price text-colorP">{{item.shopPrice}}</text>
							<text class="text-price">{{item.marketPrice}}</text>
						</view>
					</view>
				</view>
			</view>
			<noContent v-if="noContShow" :showType="'data'"></noContent>
			<tui-divider width="60%" :gradual="true" v-if="goodList.length>0">没有更多了~</tui-divider>
		</view>

		<!-- 分类 -->
		<view class="layer" v-if="isShow"></view>
		<view class="type" :style="[{top: isShow?CustomBar+48+'px':''}]">
			<view v-for="(item,index) in typeList" :key="index" :class="item.id==nowType.id?'active':''" :data-id="item.id"
			 @click="selectIndex">
				{{item.catName}}
			</view>
		</view>
	</view>
</template>

<script>
	import uniTag from "../component/uni-tag.vue";
	export default {
		components: {
			uniTag
		},
		data() {
			return {
				CustomBar: this.CustomBar,
				hotSearch: [
					"文具办公",
					"纸品湿巾",
					"水杯吸管"
				],
				nowType: {},
				typeList: [],
				isShow: false,
				lastPage: '',
				page: 1,
				goodList: [],
				noContShow: false
			}
		},
		methods: {
			nav(e){
				var url = e.currentTarget.dataset.url
				if(url){
					uni.navigateTo({
						url: url
					});
				}
			},
			selectIndex(e) {
				this.nowType = this.typeList.filter(item => item.id == e.currentTarget.dataset.id)[0]
				this.isShow = false
				this.page = 1
				this.lastPage = ''
				this.getGoods(1)
			},
			show() {
				this.isShow = true
			},
			// 跳转
			nav(e) {
				var url = e.currentTarget.dataset.url
				if (url) {
					uni.navigateTo({
						url: url
					})
				}
			},
			// 获取巧厨乐分类(热品)
			getTypes() {
				var that = this;
				this.$request({
					url: '/ShopCats/get_cats',
					data: {
						shopId: '3'
					},
					success: res => {
						if (res.data.status == 1) {
							that.typeList = res.data.data
							uni.hideLoading()
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			// 获取巧厨乐分类(热品)
			getGoods(status) {
				var that = this;
				if(status==1){ 
					that.goodList = []
				}
				this.$request({
					url: '/ShopGoods/get_shop_goods',
					data: {
						shopId: '3',
						page: that.page,
						shopCatId1: that.nowType.id ? that.nowType.id : ''
					},
					success: res => {
						if (res.data.status == 1) {
							var resData = res.data.data.data
							if (that.page == 1 && res.data.data.totalNum == 0) {
								that.noContShow = true
								return
							}
							if (resData.length > 0) {
								resData.forEach(item => {
									that.goodList.push(item)
								})
							}
							that.lastPage = res.data.data.pageCount
							that.page++
							uni.hideLoading()
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
		},
		onReachBottom() {
			if (this.page > this.lastPage) {
				return
			}
			this.getGoods()
		},
		onLoad() {
			this.getGoods()
			this.getTypes()
		}
	}
</script>

<style>
	page {
		background: #fff;
	}

	.uni-tag {
		margin-right: 20rpx !important;
	}
</style>
<style scoped>
	.header {
		width: 100%;
		height: 100rpx;
		border-bottom: solid 1rpx #efefef;
		box-sizing: border-box;
		position: fixed;
		left: 0;
		padding: 0 24rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		background: #fff;
		z-index: 10;
	}

	.header .left {
		width: 244rpx;
		border-right: solid 1rpx #efefef;
		height: 56rpx;
		margin-right: 30rpx;
		padding-right: 30rpx;
		box-sizing: border-box;
		position: relative;
		display: flex;
		align-items: center;
	}

	.header .left image {
		width: 36rpx;
		height: 36rpx;
		margin-right: 10rpx;
	}

	.header .left text {
		font-size: 30rpx;
		color: #f34930;
		line-height: 36rpx;
		letter-spacing: 1rpx;
	}

	.header .left .position {
		width: 16rpx;
		height: 16rpx;
		position: absolute;
		right: 30rpx;
	}

	.header .left .position.down {
		top: 0;
	}

	.header .left .position.top {
		bottom: 0;
	}

	.tui-rolling-search {
		flex: 1;
		width: 100%;
		height: 60upx;
		line-height: 60upx;
		border-radius: 35upx;
		padding: 0 40upx 0 30upx;
		box-sizing: border-box;
		background: #fff;
		display: flex;
		align-items: center;
		flex-wrap: nowrap;
		color: #999;
		border: solid 1rpx #efefef
	}

	.tui-rolling-search icon {
		line-height: 4
	}

	.tui-category {
		font-size: 24upx;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		margin: 0;
		margin-right: 22upx;
		flex-shrink: 0;
	}

	.tui-category-scale {
		transform: scale(0.7);
		line-height: 24upx;
	}

	.tui-category .tui-icon-class {
		line-height: 20px !important;
		margin-bottom: 0 !important;
	}

	.tui-swiper {
		font-size: 26upx;
		height: 60upx;
		flex: 1;
		padding-left: 12upx;
	}

	.tui-swiper-item {
		display: flex;
		align-items: center;
	}

	.tui-hot-item {
		line-height: 26upx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.q-content {
		width: 100%;
		box-sizing: border-box;
		padding: 0 24rpx;

	}

	.q-content .q-item {
		width: 100%;
		display: flex;
		justify-content: space-between;
		padding: 15rpx 0;
	}

	.q-content .q-item image {
		width: 240rpx;
		height: 240rpx;
		margin-right: 20rpx;
		border-radius: 8rpx;
	}

	.q-content .q-item .q-info {
		flex: 1;
		height: 240rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.q-content .q-item .q-info>view:nth-child(1) {
		font-size: 30rpx;
		line-height: 48rpx;
		letter-spacing: 1rpx;
		color: #333333;
		font-weight: bold;
	}

	.q-content .q-item .q-info>view:nth-child(2) .tags {
		margin-bottom: 20rpx;
		display: flex;
		align-items: center;
		flex-wrap: wrap;
	}

	.q-content .q-item .q-info>view:nth-child(2) .tags .tag {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 0 10rpx;
		height: 30rpx;
		background-color: rgba(248, 153, 11, .3);
		border-radius: 4rpx;
		box-sizing: border-box;
		margin-right: 10rpx;
		margin-bottom: 10rpx;
	}

	.q-content .q-item .q-info>view:nth-child(2) .tags .tag image {
		width: 20rpx;
		height: 20rpx;
		margin-right: 10rpx;
	}

	.q-content .q-item .q-info>view:nth-child(2) .tags .tag text {
		letter-spacing: 1rpx;
		color: #b36f0a;
		font-size: 20rpx;
	}

	.q-content .q-item .q-info>view:nth-child(2)>view:nth-child(2) {
		display: flex;
		align-items: center;
	}

	.q-content .q-item .q-info>view:nth-child(2)>view:nth-child(2)>text:nth-child(1) {
		font-weight: bold;
		font-size: 30rpx;
		letter-spacing: 1rpx;
	}

	.q-content .q-item .q-info>view:nth-child(2)>view:nth-child(2)>text:nth-child(2) {
		font-size: 24rpx;
		text-decoration: line-through;
		letter-spacing: 1rpx;
		color: #999;
		margin-left: 20rpx;
	}

	.layer {
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.4);
		position: fixed;
		top: 0;
		left: 0;
		z-index: 8;
	}

	.type {
		width: 750rpx;
		background-color: #ffffff;
		position: fixed;
		top: -220rpx;
		left: 0;
		display: flex;
		padding: 40rpx 24rpx;
		box-sizing: border-box;
		flex-wrap: wrap;
		z-index: 9;
		transition: all 0.5s;
	}

	.type>view {
		width: 160rpx;
		height: 56rpx;
		background-color: #efefef;
		border-radius: 8rpx;
		font-size: 28rpx;
		color: #333333;
		line-height: 56rpx;
		letter-spacing: 1rpx;
		margin-right: 20rpx;
		text-align: center;
	}

	.type>view:nth-child(4n) {
		margin-right: 0rpx !important;
	}

	.type .active {
		background-color: #F34930;
		color: #fff;
	}
</style>
